package org.zgr.controller;

import cn.dev33.satoken.annotation.SaIgnore;
import common.dtos.GoodHomePageDto;
import common.dtos.ResponseResult;
import common.entity.book.BookInfo;
import common.entity.book.GoodInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.zgr.service.BookService;
import org.zgr.service.GoodsService;

import java.util.List;

/**
 * @Author: 郑国荣
 * @Date: 2024-04-03-16:53
 * @Description:
 */
@RestController
@RequestMapping("/book")
public class GoodsController {
    @Autowired
    private GoodsService goodsService;
    @Autowired
    private BookService bookService;

    @SaIgnore
    @GetMapping("/get_goods_list")
    public ResponseResult getGoodsList(){
        List<GoodInfo> goodsList = goodsService.getGoodsList();
        List<BookInfo> booksList = bookService.getBookList();
        // book_id相同的商品和书籍合并
        List<GoodHomePageDto> goodHomePageDtos = new GoodHomePageDto().mergeBookInfo(booksList, goodsList);
        return new ResponseResult<>(100, "成功", goodHomePageDtos);
    }
}
